package com.cyrus.vueboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyrus.vueboot.mapper.log.OpsLogMapper;
import com.cyrus.vueboot.pojo.log.OpsLog;
import com.cyrus.vueboot.service.OpsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/17
 */
@Service
public class OpsLogServiceImpl extends ServiceImpl<OpsLogMapper, OpsLog> implements OpsLogService {
    @Autowired
    OpsLogMapper opsLogMapper;
    @Override
    public IPage Search(Integer page, Integer size, String key) {
        Page<OpsLog> adminPage = new Page<>(page,size);
        IPage<OpsLog> result = opsLogMapper.selectPage(adminPage,
                new QueryWrapper<OpsLog>().like("username",key).or().like("ip",key));
        return result;
    }

    @Override
    public void deleteLogs(Long[] ids) {
            if (ids != null) {
                for (Long id : ids) {
                    opsLogMapper.deleteById(id);
                }
            }
        }
    }
